package com.bigdata.quality.config.converter;

import java.util.HashMap;
import java.util.Map;

public class Hive2ColumnTypeConverter implements ColumnTypeConverter {
  public static final Hive2ColumnTypeConverter instance = new Hive2ColumnTypeConverter();

  @Override
  public Map<String, String> toFlinkColumnTypeMap() {
    Map<String, String> columnTypeMap = new HashMap<>();
    // 基本类型映射
    columnTypeMap.put("char", "char(2147483647)");
    columnTypeMap.put("varchar", "varchar(2147483647)");
    columnTypeMap.put("string", "string");
    columnTypeMap.put("boolean", "boolean");
    columnTypeMap.put("tinyint", "tinyint");
    columnTypeMap.put("smallint", "smallint");
    columnTypeMap.put("int", "int");
    columnTypeMap.put("bigint", "bigint");
    columnTypeMap.put("float", "float");
    columnTypeMap.put("double", "double");
    columnTypeMap.put("decimal", "decimal(38,2)");
    columnTypeMap.put("date", "date");
    columnTypeMap.put("timestamp", "timestamp(6)");
    columnTypeMap.put("binary", "bytes");

    // 复杂类型映射
    columnTypeMap.put("array", "array");
    columnTypeMap.put("map", "map");
    columnTypeMap.put("struct", "row");

    return columnTypeMap;
  }

  @Override
  public String convertColumnType(Map<String, String> flinkColumnTypeMap, String sourceColumnType) {
    return ColumnTypeConverter.super.convertColumnType(flinkColumnTypeMap, sourceColumnType);
  }
}
